import type { ApiResponse, User, LearningProgress, LeaderboardEntry } from '../types/index';

export const userApi = {
  async getProfile(): Promise<ApiResponse<User>> {
    const response = await fetch('/api/user/profile');
    return response.json();
  },

  async updateProfile(data: Partial<User>): Promise<ApiResponse<User>> {
    const response = await fetch('/api/user/profile', {
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(data),
    });
    return response.json();
  },

  async getLearningProgress(): Promise<ApiResponse<LearningProgress[]>> {
    const response = await fetch('/api/user/learning-progress');
    return response.json();
  },

  async getLeaderboard(type: string): Promise<ApiResponse<LeaderboardEntry[]>> {
    const response = await fetch(`/api/user/leaderboard?type=${type}`);
    return response.json();
  }
};